<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page.sync="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
      <template slot="menuLeft">
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   plain
                   v-if="permission.dtmexpfilesum_delete"
                   @click="handleDelete">删 除
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
  import {getList, getDetail, add, update, remove} from "@/api/demo/dtmexpfilesum";
  import {mapGetters} from "vuex";

  export default {
    data() {
      return {
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          height:'auto',
          calcHeight: 30,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: true,
          selection: true,
          dialogClickModal: false,
          column: [
            {
              label: "清算日期",
              prop: "liqDate",
              rules: [{
                required: true,
                message: "请输入清算日期",
                trigger: "blur"
              }]
            },
            {
              label: "服务商",
              prop: "liqCode",
              rules: [{
                required: true,
                message: "请输入服务商",
                trigger: "blur"
              }]
            },
            {
              label: "文件名称",
              prop: "fileName",
              rules: [{
                required: true,
                message: "请输入文件名称",
                trigger: "blur"
              }]
            },
            {
              label: "文件包笔数",
              prop: "fileRecordTalCnt",
              rules: [{
                required: true,
                message: "请输入文件包笔数",
                trigger: "blur"
              }]
            },
            {
              label: "文件包金额",
              prop: "fileRecordTalAmt",
              rules: [{
                required: true,
                message: "请输入文件包金额",
                trigger: "blur"
              }]
            },
            {
              label: "清算结果笔数",
              prop: "validDataTalCnt",
              rules: [{
                required: true,
                message: "请输入清算结果笔数",
                trigger: "blur"
              }]
            },
            {
              label: "清算结果金额",
              prop: "validDataTalAmt",
              rules: [{
                required: true,
                message: "请输入清算结果金额",
                trigger: "blur"
              }]
            },
            {
              label: "挂起数据笔数",
              prop: "uncrtDataTalCnt",
              rules: [{
                required: true,
                message: "请输入挂起数据笔数",
                trigger: "blur"
              }]
            },
            {
              label: "挂起数据金额",
              prop: "uncrtDataTalAmt",
              rules: [{
                required: true,
                message: "请输入挂起数据金额",
                trigger: "blur"
              }]
            },
            {
              label: "TAC异常笔数",
              prop: "tacDataTalCnt",
              rules: [{
                required: true,
                message: "请输入TAC异常笔数",
                trigger: "blur"
              }]
            },
            {
              label: "TAC异常金额",
              prop: "tacDataTalAmt",
              rules: [{
                required: true,
                message: "请输入TAC异常金额",
                trigger: "blur"
              }]
            },
            {
              label: "黑名单笔数",
              prop: "blackDataTalCnt",
              rules: [{
                required: true,
                message: "请输入黑名单笔数",
                trigger: "blur"
              }]
            },
            {
              label: "黑名单金额",
              prop: "blackDataTalAmt",
              rules: [{
                required: true,
                message: "请输入黑名单金额",
                trigger: "blur"
              }]
            },
            {
              label: "交易类型错误笔数",
              prop: "wttDataTalCnt",
              rules: [{
                required: true,
                message: "请输入交易类型错误笔数",
                trigger: "blur"
              }]
            },
            {
              label: "交易类型错误金额",
              prop: "wttDataTalAmt",
              rules: [{
                required: true,
                message: "请输入交易类型错误金额",
                trigger: "blur"
              }]
            },
            {
              label: "与历史记录重复笔数",
              prop: "dwhDataTalCnt",
              rules: [{
                required: true,
                message: "请输入与历史记录重复笔数",
                trigger: "blur"
              }]
            },
            {
              label: "与历史记录重复金额",
              prop: "dwhDataTalAmt",
              rules: [{
                required: true,
                message: "请输入与历史记录重复金额",
                trigger: "blur"
              }]
            },
            {
              label: "文件内记录重复笔数",
              prop: "difDataTalCnt",
              rules: [{
                required: true,
                message: "请输入文件内记录重复笔数",
                trigger: "blur"
              }]
            },
            {
              label: "文件内记录重复金额",
              prop: "difDataTalAmt",
              rules: [{
                required: true,
                message: "请输入文件内记录重复金额",
                trigger: "blur"
              }]
            },
            {
              label: "联机充值无效笔数",
              prop: "iorDataTalCnt",
              rules: [{
                required: true,
                message: "请输入联机充值无效笔数",
                trigger: "blur"
              }]
            },
            {
              label: "联机充值无效金额",
              prop: "iorDataTalAmt",
              rules: [{
                required: true,
                message: "请输入联机充值无效金额",
                trigger: "blur"
              }]
            },
            {
              label: "SAM卡不详笔数",
              prop: "samDataTalCnt",
              rules: [{
                required: true,
                message: "请输入SAM卡不详笔数",
                trigger: "blur"
              }]
            },
            {
              label: "SAM卡不详金额",
              prop: "samDataTalAmt",
              rules: [{
                required: true,
                message: "请输入SAM卡不详金额",
                trigger: "blur"
              }]
            },
            {
              label: "其它笔数",
              prop: "otherDataTalCnt",
              rules: [{
                required: true,
                message: "请输入其它笔数",
                trigger: "blur"
              }]
            },
            {
              label: "其它金额",
              prop: "otherDataTalAmt",
              rules: [{
                required: true,
                message: "请输入其它金额",
                trigger: "blur"
              }]
            },
            {
              label: "记录批次ID",
              prop: "recBatchId",
              rules: [{
                required: true,
                message: "请输入记录批次ID",
                trigger: "blur"
              }]
            },
            {
              label: "记录日期",
              prop: "recDate",
              rules: [{
                required: true,
                message: "请输入记录日期",
                trigger: "blur"
              }]
            },
          ]
        },
        data: []
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.dtmexpfilesum_add, false),
          viewBtn: this.vaildData(this.permission.dtmexpfilesum_view, false),
          delBtn: this.vaildData(this.permission.dtmexpfilesum_delete, false),
          editBtn: this.vaildData(this.permission.dtmexpfilesum_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {
      rowSave(row, done, loading) {
        add(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          window.console.log(error);
        });
      },
      rowUpdate(row, index, done, loading) {
        update(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          console.log(error);
        });
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(this.ids);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getDetail(this.form.id).then(res => {
            this.form = res.data.data;
          });
        }
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      }
    }
  };
</script>

<style>
</style>
